package cn.itsource.pethome.basic.service.impl;

import cn.itsource.pethome.basic.mapper.BaseMapper;
import cn.itsource.pethome.basic.query.BaseQuery;
import cn.itsource.pethome.basic.service.IBaseService;
import cn.itsource.pethome.basic.util.PageList;
import cn.itsource.pethome.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description: 描述:
 * @date: 2020/8/10 10:06
 * @author: summer
 * version: 1.0
 */
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    /**
     * 功能描述: 修改部门
     * @param t
     * @return: void
     * @Date: 2020/8/4
     */
    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    /**
     * 功能描述: 根据id删除部门
     * @param id
     * @return: void
     * @Date: 2020/8/4
     */
    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    /**
     * 功能描述: 根据id查询单个部门对象
     * @param id
     * @return: cn.itsource.pethome.org.domain.Department
     * @Date: 2020/8/4
     */
    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    /**
     * 功能描述: 查询整个部门
     * @param
     * @return: java.util.List<cn.itsource.pethome.org.domain.Department>
     * @Date: 2020/8/4
     */
    @Override
    public PageList<T> loadAll(BaseQuery baseQuery) {
        Long total = baseMapper.findCountAll(baseQuery);
        if(total.equals(0L)){
            return new PageList();
        }
        List<T> list = baseMapper.loadAll(baseQuery);
        return new PageList<T>(total,list);
    }

    /**
     * 功能描述: 根据id，批量删除部门列表
     * @param ids 数组 id
     * @return: void
     * @Date: 2020/8/8
     */
    @Override
    public void batchDel(Long[] ids) {
        baseMapper.batchDel(ids);
    }

    @Override
    public List<T> findDepartment() {
        return baseMapper.findDepartment();
    }
}
